﻿/*=============================================================================================
	TASK 11:                                                       { Operators and Expressions}
	Write an expression that extracts from a given integer i the value of a given bit number b.
    Example: i=5; b=2 => value=1.         
=============================================================================================*/

using System;

class ExtractBit
{
    static void Main()
    {
        Console.Write("Enter integer number:");
        int v = int.Parse(Console.ReadLine());

        Console.WriteLine("number in binary is:{0}", Convert.ToString(v, 2));
        
        Console.Write("Enter position which you want to check:");
        int p = int.Parse(Console.ReadLine());
        
        int mask = 1 << p;
        int numberAndMask = v & mask;
        int position1Bit = numberAndMask >> p;
        
        Console.WriteLine("The bit in position:{0} is:{1}",p,position1Bit);
    }
}

